
/*防Android提示框*/
var toast = new Toast();
function Toast() {

    //提示框的html代码
    var _toast_html = '<div id="floatTS"><div style="width: 100%; height: 100%; background-color: Black; position: fixed;z-index: 9999999999; opacity: 0.3;display:none;"></div><div style="width: 100%; height: 45px; left: 0; top: 50%; position: fixed; z-index:99999999999;"align="center"><div id="TStxt" style = "padding:10px; border-radius:5px; line-height:30px; background-color:Black; color:White; width:200px; display:block; opacity:0.8;"></div></div></div>';
    var maxOpacity = 100; //透明度的最大值
    var opacity = 0; //当前透明度值
    var tWaite = 1000; //弹出提示停留时间(毫秒)
    var tSpeed = 10; //提示框小时速度
    var disOpacity = 0.8; //显示时透明度值

    this.show = function (msg) {

        //先停止等待
        wait.dismiss();

        if ($("#TStxt").length < 1) {
            $("body").prepend(_toast_html);
        }
        else {
            $("#floatTS").css("display", "");
        }
        $("#TStxt").text(msg);
        if (opacity < 1) {
            opacity = maxOpacity;
            this.dismiss();
        } else {
            opacity = maxOpacity;
        }
    }

    //隐藏
    this.dismiss = function () {

        if (opacity < 0) {
            $("#floatTS").css("display", "none");
            return false;
        }
        $("#TStxt").css("opacity", opacity / maxOpacity * disOpacity);
        if (opacity == maxOpacity) {
            opacity--;
            setTimeout(function () { toast.dismiss(); }, tWaite);
        }
        else {
            opacity--;
            setTimeout(function () { toast.dismiss(); }, tSpeed);
        }
    }

    //成功提示框
    this.success = function (msg) { //成功提示框
        var _success_html='<div id="toast" ><div class="weui-mask_transparent"></div><div class="weui-toast"><i class="weui-icon-success-no-circle weui-icon_toast"></i><p class="weui-toast__content">' + msg + '</p></div></div>'
        $("body").prepend(_success_html);
    }
    setTimeout(function(){
        $("#toast").hide()
    },2000)
}

//等待对话框
var wait = new Wait();
function Wait() {

    //等待框html代码
    var _wait_html = '<div id="floatWait"><div style="width: 100%; height: 100%; background-color: Black; position: fixed;z-index: 9999; opacity: 0.3;display:none;"></div><div style="width: 100%; height: 45px; left: 0; top: 50%; position: fixed; z-index: 1000;"align="center"><div style = "padding:10px; border-radius:5px; line-height:30px; background-color:Black; color:White; width:200px; display:block; opacity:0.8;"><span id = "msg"></span><span id="dot"></span></div></div></div>';
    this.isShow = false;
    this.show = function (msg) {

        if ($("#dot").length < 1) {
            $("body").prepend(_wait_html);
        }
        else {
            $("#floatWait").css("display", "");
        }
        $("#msg").text(msg);
        if (!this.isShow) {
            this.isShow = true;
            this.action();
        }
    }
    
    
    this.loading = function (msg,isShow=true){ //loading加载
        var loading = weui.loading(msg);
        if(isShow == false){
            loading.hide();
        }
    }
   

    
    //动画
    this.action = function () {

        if ($("#dot").text().length > 5) {
            $("#dot").text("·");
        }
        else {
            $("#dot").text($("#dot").text() + "·");
        }
        if (this.isShow) {
            setTimeout(function () { wait.action(); }, 500);
        }

    }

    this.dismiss = function () {
        this.isShow = false;
        $("#floatWait").css("display", "none");
    }

}


